package com.wangsh.usersCenter.users.service.impl;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.wangsh.usersCenter.common.pojo.ApiResponse;
import com.wangsh.usersCenter.common.pojo.ApiResponseEnum;
import com.wangsh.usersCenter.common.pojo.JSONEnum;
import com.wangsh.usersCenter.common.service.BaseServiceImpl;
import com.wangsh.usersCenter.common.util.ConstatFinalUtil;
import com.wangsh.usersCenter.common.util.PageInfoUtil;
import com.wangsh.usersCenter.system.service.ISystemDbService;
import com.wangsh.usersCenter.users.dao.IAAdminsDao;
import com.wangsh.usersCenter.users.dao.IAMenuDao;
import com.wangsh.usersCenter.users.dao.IARoleDao;
import com.wangsh.usersCenter.users.dao.IARoleMenuDao;
import com.wangsh.usersCenter.users.pojo.AAdmins;
import com.wangsh.usersCenter.users.pojo.AMenu;
import com.wangsh.usersCenter.users.pojo.AMenuEnum;
import com.wangsh.usersCenter.users.pojo.ARole;
import com.wangsh.usersCenter.users.pojo.ARoleMenu;
import com.wangsh.usersCenter.users.service.IRbacDbService;
import com.wangsh.usersCenter.users.service.IUsersDbService;

/**
 * 用户的service
 * 
 * @author Wangsh
 */
@Service("rbacDbService")
public class RbacDbServiceImpl extends BaseServiceImpl implements IRbacDbService
{
	@Resource
	private IAMenuDao menuDao;
	@Resource
	private IARoleDao roleDao;
	@Resource
	private IARoleMenuDao roleMenuDao;
	@Resource
	private ISystemDbService systemDbService;
	@Resource
	private IAAdminsDao adminsDao;
	@Resource
	private IUsersDbService usersDbService;
	
	private List<AMenu> result ;

	/* == 菜单表实现操作开始 == */

	@Override
	public ApiResponse<Object> saveOneMenuService(AMenu menu)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		try
		{
			menu.setCreateTime(new Date());
			menu.setUpdateTime(new Date());
			int res = this.menuDao.save(menu);
			if (res > 0)
			{
				Map<String, Object> dataMap = new HashMap<String, Object>();
				dataMap.put(JSONEnum.EFFECT.getName(), res);
				dataMap.put(JSONEnum.ID.getName(), menu.getId());
				dataMap.put(ApiResponseEnum.NAME_ONE.getName(), menu);
				apiResponse.setDataOne(dataMap);

				/* 添加当前节点,如果父节点要是能够查询到,直接变成叶子节点 */
				Map<String, Object> condMap = new HashMap<String, Object>();
				if (menu.getParentId()!=0)
				{
					condMap.put("id", menu.getParentId());
					ApiResponse<AMenu> parentMenuResponse = this.findOneMenuService(condMap);
					AMenu parentMenu = parentMenuResponse.getDataOneJava();
					if (parentMenu != null)
					{
						parentMenu.setIsLeafStatus(AMenuEnum.ISLEAF_NOLEAF.getStatus());
						this.updateOneMenuService(parentMenu);
					}
				}
				apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
			} else
			{
				apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
			}
			apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""),
					Collections.EMPTY_MAP);
		} catch (Exception e)
		{
			ConstatFinalUtil.SYS_LOGGER.error("保存一条记录失败了", e);
			apiResponse.setCode(ApiResponseEnum.STATUS_SERVER_ERROR.getStatus());
			Map<String, String> infoMap = new HashMap<String, String>();
			/* 报错信息的占位符 */
			infoMap.put("errinfo", e.toString());
			apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), infoMap);
		}
		return apiResponse;
	}

	@Override
	public ApiResponse<Object> updateOneMenuService(AMenu menu)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		try
		{
			menu.setUpdateTime(new Date());
			int res = this.menuDao.update(menu);
			if (res > 0)
			{
				Map<String, Object> dataMap = new HashMap<String, Object>();
				dataMap.put(JSONEnum.EFFECT.getName(), res);
				dataMap.put(JSONEnum.ID.getName(), menu.getId());
				dataMap.put(ApiResponseEnum.NAME_ONE.getName(), menu);
				apiResponse.setDataOne(dataMap);

				apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
			} else
			{
				apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
			}
			apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""),
					Collections.EMPTY_MAP);
		} catch (Exception e)
		{
			ConstatFinalUtil.SYS_LOGGER.error("更新一条记录失败了", e);
			apiResponse.setCode(ApiResponseEnum.STATUS_SERVER_ERROR.getStatus());
			Map<String, String> infoMap = new HashMap<String, String>();
			/* 报错信息的占位符 */
			infoMap.put("errinfo", e.toString());
			apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), infoMap);
		}
		return apiResponse;
	}

	@Override
	public ApiResponse<Object> deleteOneMenuService(Map<String, Object> condMap)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		try
		{
			int res = this.menuDao.delete(condMap);
			if (res > 0)
			{
				Map<String, Object> dataMap = new HashMap<String, Object>();
				dataMap.put(JSONEnum.EFFECT.getName(), res);
				apiResponse.setDataOne(dataMap);

				apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
			} else
			{
				apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
			}
			apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""),
					Collections.EMPTY_MAP);
		} catch (Exception e)
		{
			ConstatFinalUtil.SYS_LOGGER.error("删除一条记录失败了", e);
			apiResponse.setCode(ApiResponseEnum.STATUS_SERVER_ERROR.getStatus());
			Map<String, String> infoMap = new HashMap<String, String>();
			/* 报错信息的占位符 */
			infoMap.put("errinfo", e.toString());
			apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), infoMap);
		}
		return apiResponse;
	}

	@Override
	public ApiResponse<AMenu> findOneMenuService(Map<String, Object> condMap)
	{
		ApiResponse<AMenu> apiResponse = new ApiResponse<AMenu>();

		Map<String, AMenu> data = new HashMap<String, AMenu>();
		try
		{
			ApiResponse<AAdmins> findOneAdminsService = null;
			AMenu menu = this.menuDao.findOne(condMap);
			condMap.clear();
			condMap.put("id", menu.getCreateId());
			if (menu.getCreateId() == menu.getUpdateId())
			{
				findOneAdminsService = this.usersDbService.findOneAdminsService(condMap);
				menu.setCreateAdmins(findOneAdminsService.getDataOneJava());
				menu.setUpdateAdmins(findOneAdminsService.getDataOneJava());
			} else
			{
				findOneAdminsService = this.usersDbService.findOneAdminsService(condMap);
				menu.setCreateAdmins(findOneAdminsService.getDataOneJava());
				condMap.put("id", menu.getUpdateId());
				findOneAdminsService = this.usersDbService.findOneAdminsService(condMap);
				menu.setUpdateAdmins(findOneAdminsService.getDataOneJava());
			}
			condMap.put("id", menu.getParentId());
			condMap.remove("parentId");
			AMenu findOne = this.menuDao.findOne(condMap);
			menu.setParentMenu(findOne);
			data.put(ApiResponseEnum.NAME_ONE.getName(), menu);
			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
			/* 将结果放到JSON中 */
			apiResponse.setDataOne(data);
			apiResponse.setDataOneJava(menu);
			apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""),
					Collections.EMPTY_MAP);
		} catch (Exception e)
		{
			ConstatFinalUtil.SYS_LOGGER.error("查询一条记录失败了", e);
			apiResponse.setCode(ApiResponseEnum.STATUS_SERVER_ERROR.getStatus());
			Map<String, String> infoMap = new HashMap<String, String>();
			/* 报错信息的占位符 */
			infoMap.put("errinfo", e.toString());
			apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), infoMap);
		}
		return apiResponse;
	}

	@Override
	public ApiResponse<AMenu> findCondListMenuService(PageInfoUtil pageInfoUtil, Map<String, Object> condMap)
	{
		ApiResponse<AMenu> apiResponse = new ApiResponse<AMenu>();
		// code=0
		apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		List<AMenu> menuList = Collections.EMPTY_LIST;

		Map<String, List<AMenu>> dataList = new HashMap<String, List<AMenu>>();
		try
		{
			
			/* 对关键字进行模糊匹配 */
			if (condMap.get("keyword") != null && !"".equalsIgnoreCase(condMap.get("keyword") + ""))
			{
				condMap.put("keyword", "%" + condMap.get("keyword") + "%");
			}

			/* 设置分页相关信息 */
			if (pageInfoUtil != null)
			{
				/* 设置分页信息 pageInfoUtil默认当前页为1,每页10条 */
				Page page = PageHelper.startPage(pageInfoUtil.getCurrentPage(), pageInfoUtil.getPageSize());
				menuList = this.menuDao.findList(condMap);
				pageInfoUtil.setTotalRecord(Integer.valueOf(page.getTotal() + ""));
				/* 向接口中放分页信息 */
				apiResponse.setPageInfoUtil(pageInfoUtil);
			} else
			{
				menuList = this.menuDao.findList(condMap);
			}
			//这个是打开菜单树形结构
			if (condMap.get("menuTree")!=null&&!"".equals(condMap.get("menuTree"))&&condMap.get("menuTree").equals("menuTree"))
			{

				condMap.clear();
				condMap.put("status", 1);
				condMap.put("parentId","0");
				List<AMenu> findList = this.menuDao.findList(condMap);
				Map<String, List<AMenu>> resultMap = new HashMap<String, List<AMenu>>();
				for (int i = 0; i < findList.size(); i++)
				{
					result = new ArrayList<AMenu>();
					result.clear();
					result.add(findList.get(i));
					this.ceshi(menuList, findList.get(i).getId());
					if(result != null ) {
						resultMap.put(i+"",result);
					}
				}
				
				apiResponse.setDataList(resultMap);
				return apiResponse;
			}
			//这个是角色授权
			else if (condMap.get("menuTree")!=null&&!"".equals(condMap.get("menuTree"))&&condMap.get("menuTree").equals("menuTreeRole"))
			{
				PageInfoUtil pageInfoUtilRes = new PageInfoUtil();
				for (Iterator iterator = menuList.iterator(); iterator.hasNext();)
				{
					AMenu menu = (AMenu) iterator.next();
					condMap.put("menuId", menu.getId());
					/* 根据角色id和菜单id查找 */
					this.findCondListRoleMenuService(pageInfoUtilRes, condMap);
					if (pageInfoUtilRes.getTotalRecord() > 0)
					{
						menu.setRoleMenuFlag(true);
					}
				}
				condMap.clear();
				condMap.put("status", 1);
				condMap.put("parentId","0");
				List<AMenu> findList = this.menuDao.findList(condMap);
				Map<String, List<AMenu>> resultMap = new HashMap<String, List<AMenu>>();
				for (int i = 0; i < findList.size(); i++)
				{
					result = new ArrayList<AMenu>();
					result.clear();
					result.add(findList.get(i));
					this.ceshi(menuList, findList.get(i).getId());
					if(result != null ) {
						resultMap.put(i+"",result);
					}
				}
				
				apiResponse.setDataList(resultMap);
				return apiResponse;
			}
			/* 查询菜单栏中,是否有角色和菜单Id */
			String roleId = condMap.get("roleId") + "";
			PageInfoUtil pageInfoUtilRes = new PageInfoUtil();
			for (Iterator iterator = menuList.iterator(); iterator.hasNext();)
			{
				AMenu menu = (AMenu) iterator.next();
				condMap.put("id", menu.getId());
				if (!"null".equalsIgnoreCase(roleId))
				{
					condMap.put("menuId", menu.getId());
					/* 根据角色id和菜单id查找 */
					this.findCondListRoleMenuService(pageInfoUtilRes, condMap);
					if (pageInfoUtilRes.getTotalRecord() > 0)
					{
						menu.setRoleMenuFlag(true);
					}
				}
				ApiResponse<AMenu> findOneMenuService = this.findOneMenuService(condMap);
				menu.setCreateAdmins(findOneMenuService.getDataOneJava().getCreateAdmins());
				menu.setUpdateAdmins(findOneMenuService.getDataOneJava().getUpdateAdmins());
				menu.setParentMenu(findOneMenuService.getDataOneJava().getParentMenu());
			}
			/* 将结果放到JSON中 */
			dataList.put(ApiResponseEnum.NAME_LIST.getName(), menuList);
			apiResponse.setDataListJava(menuList);
			apiResponse.setDataList(dataList);
			apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""),
					Collections.EMPTY_MAP);
		} catch (Exception e)
		{
			ConstatFinalUtil.SYS_LOGGER.error("查询多条记录失败了", e);
			apiResponse.setCode(ApiResponseEnum.STATUS_SERVER_ERROR.getStatus());
			Map<String, String> infoMap = new HashMap<String, String>();
			/* 报错信息的占位符 */
			infoMap.put("errinfo", e.toString());
			apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), infoMap);
		}
		return apiResponse;
	}
	//获取父id为parId的所有菜单,菜单都放在全局变量的result里面了  不要在意这个方法名
	public void ceshi(List<AMenu> meneList , int parId)
	{
		for(int i = 0 ; i < meneList.size() ; i ++) {
			int parentId = meneList.get(i).getParentId();
			if(parentId == parId) {
				result.add(meneList.get(i));
					ceshi(meneList, meneList.get(i).getId());
			}
		}
	}

	/* == 菜单表实现操作结束 == */

	/* == 角色表实现操作开始 == */

	@Override
	public ApiResponse<Object> saveOneRoleService(ARole role)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		try
		{

			int res = this.roleDao.save(role);
			if (res > 0)
			{
				Map<String, Object> dataMap = new HashMap<String, Object>();
				dataMap.put(JSONEnum.EFFECT.getName(), res);
				dataMap.put(JSONEnum.ID.getName(), role.getId());
				dataMap.put(ApiResponseEnum.NAME_ONE.getName(), role);
				apiResponse.setDataOne(dataMap);

				apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
			} else
			{
				apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
			}
			apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""),
					Collections.EMPTY_MAP);
		} catch (Exception e)
		{
			ConstatFinalUtil.SYS_LOGGER.error("保存一条记录失败了", e);
			apiResponse.setCode(ApiResponseEnum.STATUS_SERVER_ERROR.getStatus());
			Map<String, String> infoMap = new HashMap<String, String>();
			/* 报错信息的占位符 */
			infoMap.put("errinfo", e.toString());
			apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), infoMap);
		}
		return apiResponse;
	}

	@Override
	public ApiResponse<Object> updateOneRoleService(ARole role)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		try
		{
			int res = this.roleDao.update(role);
			if (res > 0)
			{
				Map<String, Object> dataMap = new HashMap<String, Object>();
				dataMap.put(JSONEnum.EFFECT.getName(), res);
				dataMap.put(JSONEnum.ID.getName(), role.getId());
				dataMap.put(ApiResponseEnum.NAME_ONE.getName(), role);
				apiResponse.setDataOne(dataMap);

				apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
			} else
			{
				apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
			}
			apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""),
					Collections.EMPTY_MAP);
		} catch (Exception e)
		{
			ConstatFinalUtil.SYS_LOGGER.error("更新一条记录失败了", e);
			apiResponse.setCode(ApiResponseEnum.STATUS_SERVER_ERROR.getStatus());
			Map<String, String> infoMap = new HashMap<String, String>();
			/* 报错信息的占位符 */
			infoMap.put("errinfo", e.toString());
			apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), infoMap);
		}
		return apiResponse;
	}

	@Override
	public ApiResponse<Object> deleteOneRoleService(Map<String, Object> condMap)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		try
		{
			int res = this.roleDao.delete(condMap);
			if (res > 0)
			{
				Map<String, Object> dataMap = new HashMap<String, Object>();
				dataMap.put(JSONEnum.EFFECT.getName(), res);
				apiResponse.setDataOne(dataMap);

				apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
			} else
			{
				apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
			}
			apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""),
					Collections.EMPTY_MAP);
		} catch (Exception e)
		{
			ConstatFinalUtil.SYS_LOGGER.error("删除一条记录失败了", e);
			apiResponse.setCode(ApiResponseEnum.STATUS_SERVER_ERROR.getStatus());
			Map<String, String> infoMap = new HashMap<String, String>();
			/* 报错信息的占位符 */
			infoMap.put("errinfo", e.toString());
			apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), infoMap);
		}
		return apiResponse;
	}

	@Override
	public ApiResponse<ARole> findOneRoleService(Map<String, Object> condMap)
	{
		ApiResponse<ARole> apiResponse = new ApiResponse<ARole>();

		Map<String, ARole> data = new HashMap<String, ARole>();
		try
		{
			ARole role = this.roleDao.findOne(condMap);
			if(role != null)
			{
				condMap.clear();
				condMap.put("id", role.getCreateId());
				if (role.getCreateId() == role.getUpdateId())
				{
					AAdmins findOne = this.adminsDao.findOne(condMap);
					role.setCreateAdmins(findOne);
					role.setUpdateAdmins(findOne);
				} else
				{
					AAdmins findOne = this.adminsDao.findOne(condMap);
					role.setCreateAdmins(findOne);
					condMap.put("id", role.getUpdateId());
					AAdmins findOne2 = this.adminsDao.findOne(condMap);
					role.setUpdateAdmins(findOne2);
				}
			}
			data.put(ApiResponseEnum.NAME_ONE.getName(), role);
			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
			/* 将结果放到JSON中 */
			apiResponse.setDataOne(data);
			apiResponse.setDataOneJava(role);
			apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""),
					Collections.EMPTY_MAP);
		} catch (Exception e)
		{
			ConstatFinalUtil.SYS_LOGGER.error("查询一条记录失败了", e);
			apiResponse.setCode(ApiResponseEnum.STATUS_SERVER_ERROR.getStatus());
			Map<String, String> infoMap = new HashMap<String, String>();
			/* 报错信息的占位符 */
			infoMap.put("errinfo", e.toString());
			apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), infoMap);
		}
		return apiResponse;
	}

	@Override
	public ApiResponse<ARole> findCondListRoleService(PageInfoUtil pageInfoUtil, Map<String, Object> condMap)
	{
		ApiResponse<ARole> apiResponse = new ApiResponse<ARole>();
		apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		List<ARole> roleList = Collections.EMPTY_LIST;

		Map<String, List<ARole>> dataList = new HashMap<String, List<ARole>>();
		try
		{

			/* 对关键字进行模糊匹配 */
			if (condMap.get("keyword") != null && !"".equalsIgnoreCase(condMap.get("keyword") + ""))
			{
				condMap.put("keyword", "%" + condMap.get("keyword") + "%");
			}

			/* 设置分页相关信息 */
			if (pageInfoUtil != null)
			{
				/* 设置分页信息 */
				Page page = PageHelper.startPage(pageInfoUtil.getCurrentPage(), pageInfoUtil.getPageSize());
				roleList = this.roleDao.findList(condMap);
				pageInfoUtil.setTotalRecord(Integer.valueOf(page.getTotal() + ""));
				/* 向接口中放分页信息 */
				apiResponse.setPageInfoUtil(pageInfoUtil);
			} else
			{
				roleList = this.roleDao.findList(condMap);
			}
			/* 将结果放到JSON中 */
			dataList.put(ApiResponseEnum.NAME_LIST.getName(), roleList);
			apiResponse.setDataListJava(roleList);
			apiResponse.setDataList(dataList);
			apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""),
					Collections.EMPTY_MAP);
		} catch (Exception e)
		{
			ConstatFinalUtil.SYS_LOGGER.error("查询多条记录失败了", e);
			apiResponse.setCode(ApiResponseEnum.STATUS_SERVER_ERROR.getStatus());
			Map<String, String> infoMap = new HashMap<String, String>();
			/* 报错信息的占位符 */
			infoMap.put("errinfo", e.toString());
			apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), infoMap);
		}
		return apiResponse;
	}

	/**
	 * 角色授权->获取权限
	 */
	@Override
	public ApiResponse<AMenu> getPermission(Map<String, Object> condMap)
	{
		ApiResponse<AMenu> aMenuList = adminsDao.getPermission(condMap);
		return aMenuList;
	}

	/* == 角色操作结束 == */

	/* == 角色菜单操作开始 == */

	@Override
	public ApiResponse<Object> saveOneRoleMenuService(ARoleMenu roleMenu)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		try
		{
			roleMenu.setCreateTime(new Date());
			roleMenu.setUpdateTime(new Date());
			int res = this.roleMenuDao.save(roleMenu);
			if (res > 0)
			{
				Map<String, Object> dataMap = new HashMap<String, Object>();
				dataMap.put(JSONEnum.EFFECT.getName(), res);
				dataMap.put(JSONEnum.ID.getName(), roleMenu.getId());
				dataMap.put(ApiResponseEnum.NAME_ONE.getName(), roleMenu);
				apiResponse.setDataOne(dataMap);

				apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
			} else
			{
				apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
			}
			apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""),
					Collections.EMPTY_MAP);
		} catch (Exception e)
		{
			ConstatFinalUtil.SYS_LOGGER.error("保存一条记录失败了", e);
			apiResponse.setCode(ApiResponseEnum.STATUS_SERVER_ERROR.getStatus());
			Map<String, String> infoMap = new HashMap<String, String>();
			/* 报错信息的占位符 */
			infoMap.put("errinfo", e.toString());
			apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), infoMap);
		}
		return apiResponse;
	}

	/* 批量添加 */
	public ApiResponse<Object> saveBatchRoleMenuService(List<Map> list)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		try
		{
			int res = this.roleMenuDao.saveBatch(list);
			if (res > 0)
			{
				Map<String, Object> dataMap = new HashMap<String, Object>();
				dataMap.put(JSONEnum.EFFECT.getName(), res);
				apiResponse.setDataOne(dataMap);

				apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
			} else
			{
				apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
			}
			apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""),
					Collections.EMPTY_MAP);
		} catch (Exception e)
		{
			ConstatFinalUtil.SYS_LOGGER.error("保存多条记录失败了", e);
			apiResponse.setCode(ApiResponseEnum.STATUS_SERVER_ERROR.getStatus());
			Map<String, String> infoMap = new HashMap<String, String>();
			/* 报错信息的占位符 */
			infoMap.put("errinfo", e.toString());
			apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), infoMap);
		}
		return apiResponse;
	}

	@Override
	public ApiResponse<Object> updateOneRoleMenuService(ARoleMenu roleMenu)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		try
		{
			int res = this.roleMenuDao.update(roleMenu);
			if (res > 0)
			{
				Map<String, Object> dataMap = new HashMap<String, Object>();
				dataMap.put(JSONEnum.EFFECT.getName(), res);
				dataMap.put(JSONEnum.ID.getName(), roleMenu.getId());
				dataMap.put(ApiResponseEnum.NAME_ONE.getName(), roleMenu);
				apiResponse.setDataOne(dataMap);

				apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
			} else
			{
				apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
			}
			apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""),
					Collections.EMPTY_MAP);
		} catch (Exception e)
		{
			ConstatFinalUtil.SYS_LOGGER.error("更新一条记录失败了", e);
			apiResponse.setCode(ApiResponseEnum.STATUS_SERVER_ERROR.getStatus());
			Map<String, String> infoMap = new HashMap<String, String>();
			/* 报错信息的占位符 */
			infoMap.put("errinfo", e.toString());
			apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), infoMap);
		}
		return apiResponse;
	}

	@Override
	public ApiResponse<Object> deleteOneRoleMenuService(Map<String, Object> condMap)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		try
		{
			int res = this.roleMenuDao.delete(condMap);
			if (res > 0)
			{
				Map<String, Object> dataMap = new HashMap<String, Object>();
				dataMap.put(JSONEnum.EFFECT.getName(), res);
				apiResponse.setDataOne(dataMap);

				apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
			} else
			{
				apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
			}
			apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""),
					Collections.EMPTY_MAP);
		} catch (Exception e)
		{
			ConstatFinalUtil.SYS_LOGGER.error("删除一条记录失败了", e);
			apiResponse.setCode(ApiResponseEnum.STATUS_SERVER_ERROR.getStatus());
			Map<String, String> infoMap = new HashMap<String, String>();
			/* 报错信息的占位符 */
			infoMap.put("errinfo", e.toString());
			apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), infoMap);
		}
		return apiResponse;
	}

	@Override
	public ApiResponse<ARoleMenu> findOneRoleMenuService(Map<String, Object> condMap)
	{
		ApiResponse<ARoleMenu> apiResponse = new ApiResponse<ARoleMenu>();

		Map<String, ARoleMenu> data = new HashMap<String, ARoleMenu>();
		try
		{
			ARoleMenu roleMenu = this.roleMenuDao.findOne(condMap);
			data.put(ApiResponseEnum.NAME_ONE.getName(), roleMenu);
			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
			/* 将结果放到JSON中 */
			apiResponse.setDataOne(data);
			apiResponse.setDataOneJava(roleMenu);
			apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""),
					Collections.EMPTY_MAP);
		} catch (Exception e)
		{
			ConstatFinalUtil.SYS_LOGGER.error("查询一条记录失败了", e);
			apiResponse.setCode(ApiResponseEnum.STATUS_SERVER_ERROR.getStatus());
			Map<String, String> infoMap = new HashMap<String, String>();
			/* 报错信息的占位符 */
			infoMap.put("errinfo", e.toString());
			apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), infoMap);
		}
		return apiResponse;
	}

	@Override
	public ApiResponse<ARoleMenu> findCondListRoleMenuService(PageInfoUtil pageInfoUtil, Map<String, Object> condMap)
	{
		ApiResponse<ARoleMenu> apiResponse = new ApiResponse<ARoleMenu>();
		// code=0
		apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		List<ARoleMenu> roleMenuList = Collections.EMPTY_LIST;

		Map<String, List<ARoleMenu>> dataList = new HashMap<String, List<ARoleMenu>>();
		try
		{

			/* 对关键字进行模糊匹配 */
			if (condMap.get("keyword") != null && !"".equalsIgnoreCase(condMap.get("keyword") + ""))
			{
				condMap.put("keyword", "%" + condMap.get("keyword") + "%");
			}

			/* 设置分页相关信息 */
			if (pageInfoUtil != null)
			{
				/* 设置分页信息 */
				Page page = PageHelper.startPage(pageInfoUtil.getCurrentPage(), pageInfoUtil.getPageSize());
				// 查询多条菜单
				roleMenuList = this.roleMenuDao.findList(condMap);
				pageInfoUtil.setTotalRecord(Integer.valueOf(page.getTotal() + ""));
				/* 向接口中放分页信息 */
				apiResponse.setPageInfoUtil(pageInfoUtil);
			} else
			{
				// 查询多条菜单
				roleMenuList = this.roleMenuDao.findList(condMap);
			}

			/* 将结果放到JSON中 */
			dataList.put(ApiResponseEnum.NAME_LIST.getName(), roleMenuList);
			apiResponse.setDataListJava(roleMenuList);
			apiResponse.setDataList(dataList);
			apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""),
					Collections.EMPTY_MAP);
		} catch (Exception e)
		{
			ConstatFinalUtil.SYS_LOGGER.error("查询多条记录失败了", e);
			apiResponse.setCode(ApiResponseEnum.STATUS_SERVER_ERROR.getStatus());
			Map<String, String> infoMap = new HashMap<String, String>();
			/* 报错信息的占位符 */
			infoMap.put("errinfo", e.toString());
			apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), infoMap);
		}
		return apiResponse;
	}
	/* == 角色菜单操作结束 == */

}
